package com.chessimo.printer;

import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;

import com.chessimo.config.Definitions;
import com.chessimo.main.Chess;
import com.chessimo.util.Utilities;

public class PrinterInfoTraining implements MouseListener {

	private int frameWidth;
	private int frameHeight;
	private static JButton butConfig = new JButton();
	private static JButton butBack = new JButton();
	private static JLabel mainBox = new JLabel();
	private static Border thickBorder;
	private static JScrollPane sbrText;

	public PrinterInfoTraining(int frameWidth, int frameHeight) {
		this.frameWidth = frameWidth;
		this.frameHeight = frameHeight;
	}
	
	
	public void print() {
		printButConfig("Config");
		printButBack("Back");
		printLabCentral();
	}

	public void printButConfig(String txt) {

		int pos = frameWidth - 160;

		butConfig = new JButton(txt);
		butConfig.setBounds(pos, 5, 140, 30);
		butConfig.setFont(Definitions.fontButtons);
		Chess.pInfoTraining.add(butConfig, new Integer(25));

		butConfig.addMouseListener(this);

	}

	public void printButBack(String txt) {

		int pos1 = 5;
		int pos2 = 5;

		int butWidth = 140;
		int butHeight = 30;

		butBack = new JButton(txt);
		butBack.setBounds(pos1, pos2, butWidth, butHeight);
		butBack.setFont(Definitions.fontButtons);
		Chess.pInfoTraining.add(butBack, new Integer(25));
		butBack.addMouseListener(this);

	}

	public void printLabCentral() {

		File file = new File(
				"html/pt/training_with_chessimo.html");

		String content = Utilities.getContents(file);

		int width = 500;
		int height = 600;

		int x = frameWidth / 2 - (width / 2) - 10;
		int y = frameHeight / 2 - (height / 2);

		mainBox.setOpaque(true);
		mainBox.setBackground(Definitions.bg1);
		thickBorder = new LineBorder(Definitions.border, 5);
		mainBox.setBorder(thickBorder);
		mainBox.setText("<html>" + content + "</html>");
		sbrText = new JScrollPane(mainBox);
		sbrText.setBounds(x, y, width, height);
		thickBorder = new LineBorder(Color.WHITE, 0);
		sbrText.setBorder(thickBorder);
		sbrText.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

		Chess.pInfoTraining.add(sbrText, new Integer(100));

	}

	@Override
	public void mouseClicked(MouseEvent e) {
		if (e.getSource() == butBack) {
			try {
				Chess.selector(2);
			} catch (FileNotFoundException ex) {
				Logger.getLogger(PrinterInfoTraining.class.getName()).log(
						Level.SEVERE, null, ex);
			} catch (IOException ex) {
				Logger.getLogger(PrinterInfoTraining.class.getName()).log(
						Level.SEVERE, null, ex);
			}
		}
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// throw new UnsupportedOperationException("Not supported yet.");
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// throw new UnsupportedOperationException("Not supported yet.");
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// throw new UnsupportedOperationException("Not supported yet.");
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// throw new UnsupportedOperationException("Not supported yet.");
	}

}
